﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;

namespace SW2A311A
{
    public class BuiltInOven : ElectricOven
    {
        #region Instansvariabler
        public List<String> Accessories { get; private set; }
        public bool WithCleaningFunction { get; private set; }
        #endregion

        #region Constructors
        // BuiltInOven instantieres med indput parametre til alle fields og proporties, 
        // og sender dem videre til superklasserne ElectricOven og Product den ikke selv har fields til.
        public BuiltInOven(string name, double price, Dimensions dimension,
            double volume, double energyConsumption, bool withCleaningFunction)
            : base(name, price, dimension, volume, energyConsumption)
        {
            WithCleaningFunction = withCleaningFunction;
            Accessories = new List<String>();
        }
        #endregion

        #region Metoder
        internal void AddAccessorie(string accessorieToAdd)
        {
            Accessories.Add(accessorieToAdd);
        }

        internal void RemoveAccessorie(string accessorieToRemove)
        {
            Accessories.RemoveAll(x => x == accessorieToRemove);
        }

        public override string ToString()  // ToString metode override der returnerer en string med alle fields og proporties fra BuiltInOven.
        {
            string accessoriesString = "None";
            if (Accessories.Count > 0)
                accessoriesString = string.Join(", ", Accessories);

            return string.Format
                ("Type: Builtin Oven\nManufacturer {0}\nWith cleaning function: {1}\nVolume: {2}L\nEnergyconsumption: {3}kWh\n" +
                "Energyclass: {4}\nDimensions: {5}\nSmiley: {6}\nPrice: {7:C}\nAccessories: {8}\n",
                    Name, WithCleaningFunction ? "Ja" : "Nej", Volume, EnergyConsumption,
                    EnergyClass, Dimension, Smiley, Price, accessoriesString);
        }

        public override ESmiley GetSmiley()
        {
            if (this.WithCleaningFunction)
                return ESmiley.Positive;
            else
                return ESmiley.Neutral;
        }

        #region Equalsmetoder
        public override bool Equals(object obj)
        {
            BuiltInOven p = obj as BuiltInOven;
            if (this.GetType() != obj.GetType())
                return false;

            return base.Equals(obj) &&
                Accessories == p.Accessories &&
                WithCleaningFunction == p.WithCleaningFunction;
        }

        public bool Equals(BuiltInOven p)
        {
            return base.Equals((ElectricOven)p) &&
                Accessories == p.Accessories &&
                WithCleaningFunction == p.WithCleaningFunction;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode() ^ Accessories.GetHashCode() ^
                WithCleaningFunction.GetHashCode();
        }
        #endregion
        #endregion
    }
}